package models.midas.form;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

public abstract class BaseFormBean {
	private long id;
	
	private String state;
	private boolean grammar;
	
	protected int authorId;
	protected String author;
	protected String email;	
	
	
	protected String version;
	
	protected String comments;
	protected String revisionHistory;
	
	protected String editHistory;
	
	public abstract JSONObject getJsonData() throws JSONException;
	
	protected abstract void retriveDataFromJson(JSONObject data) throws JSONException;
	
	public BaseFormBean(JSONObject data) {
		try {
			retriveDataFromJson(data);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public BaseFormBean(){}
	
	protected Map<Long,String> retriveBuildsArray(JSONArray builds) throws JSONException{
		Map<Long,String> result = new HashMap<Long,String>();
		for(int i = 0; i < builds.length(); i++){
			JSONObject build = builds.getJSONObject(i);
			result.put(build.getLong("id"), build.getString("release") + "," + build.getString("build"));
		}
		return result;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public boolean isGrammar() {
		return grammar;
	}

	public void setGrammar(boolean grammar) {
		this.grammar = grammar;
	}

	public int getAuthorId() {
		return authorId;
	}

	public void setAuthorId(int authorId) {
		this.authorId = authorId;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getRevisionHistory() {
		return revisionHistory;
	}

	public void setRevisionHistory(String revisionHistory) {
		this.revisionHistory = revisionHistory;
	}

	public String getEditHistory() {
		return editHistory;
	}

	public void setEditHistory(String editHistory) {
		this.editHistory = editHistory;
	}
}
